﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Globalization;

namespace SecureCookie.Implementation.Helper
{
    /// <summary>
    /// Helper class with extension methods around the <see cref="TraceContext" /> class.
    /// </summary>
    public static class TraceContextHelper
    {
        /// <summary>
        /// Writes the given message with the given parameters, but only when the context is enabled.
        /// </summary>
        /// <param name="context">The context on which the given message should be written</param>
        /// <param name="message">The message to write</param>
        /// <param name="args">The arguments of the message to write</param>
        public static void WriteIfEnabled(this TraceContext context, Func<string> message, Func<object[]> args)
        {
            if (context.IsEnabled)
            {
                context.Write(SecureCookieSettings.Default.TracingCategory, string.Format(CultureInfo.InvariantCulture, message(), args()));
            }
        }
    }
}
